define("login",["jquery","md5","cookie"],function () {
	return {
		//切换状态栏
		move(){
			$(".login_right ul").children("li").each(function (index,ele) {
				$(ele).click(function () {
					var $index=$(this).index()
					$(this).addClass("current").siblings().removeClass("current")
					$(".center div").eq($index).css("display","block").siblings("div").css("display","none")
				})
			})
		},
		login(eles){
			$(eles).submit(function () {
				var formData=new FormData()
				var $dataArr=$(this).serializeArray()
				$dataArr.forEach((ele,index)=>{
				if(ele.name=="upwd"){
					formData.append(ele.name,$.md5(ele.value))
				}else{
					formData.append(ele.name,ele.value)
				}
				})
				$.ajax({
					url:"../../server/login.php",
					type:"post",
					dataType:"json",
					data:formData,
					processData:false,
					contentType:false
				}).then(function (res) {
					
					sessionStorage.setItem("userInfo",JSON.stringify(res.data))
					console.log(res.data);
					alert(res.msg)
					if(res.status==1){
						var  cookielist=JSON.parse($.cookie("carts")||'[]')
						let arr=[]
						cookielist.forEach((ele,index)=>{
							ele.u_id=res.data.u_id
							console.log(res.data);
							let p=$.ajax({
								url:"../../server/addcarts.php",
								data:ele,
								type:"post",
								
							})
							arr.push(p.promise())
						})
						Promise.all(arr).then(function (res) {
							
							$.cookie("carts","",{expires:-1})
							window.location="index.html"
							
						})
					}
					
				})
				return false
			})
		}
	}
})